package com.heima.pri01;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;

public class ZifuLiu {
    public static void main(String[] args) throws UnsupportedEncodingException {
         //编码表：ASCII
         //编码：按照某种规格，把字符变成二进制，并存储到计算机中
         //解码：二进制转字符，编码和解码必须一致，否则出现乱码处理
        //byte[] getBytes()使用平台的默认字符集将该 String编码为一系列字节
        String s="好好学习，天天向上";
        byte[] bytes=s.getBytes();
        System.out.println(Arrays.toString(bytes));
        //byte[] getBytes(String charsetName)使用指定的字符集将该 String编码为一系列字节
        String s1="好好学习，天天向上";
        byte[] bytes1=s1.getBytes("utf-8");
        byte[] bytes2=s1.getBytes("GBK");
        System.out.println(Arrays.toString(bytes1));
        System.out.println(Arrays.toString(bytes2));
        // String(byte[] bytes)使用平台的默认字符集解码指定的字节数组来创建字符串
        byte[] bytes4={-27, -91, -67, -27, -91, -67, -27, -83, -90, -28, -71, -96, -17, -68, -116, -27, -92, -87, -27, -92, -87, -27, -112, -111, -28, -72, -118};
        String s3=new String(bytes4,"utf-8");
        System.out.println(s3);

        // String(byte[] bytes, String charsetName)通过指定的字符集解码指定的字节数组来创建字符串
        byte[] bytes3={-27, -91, -67, -27, -91, -67, -27, -83, -90, -28, -71, -96, -17, -68, -116, -27, -92, -87, -27, -92, -87, -27, -112, -111, -28, -72, -118};
        String s2=new String(bytes3);
        System.out.println(s2);
    }
}
